package SSF.OS.NetFlow.Filter;

import com.renesys.raceway.DML.*;

/**
 * This is for exact match.
 * <BR>
 * equals -- the value to be matched.
 */
public class ExactRange implements Range
{
    Object reference = null;

    /**
     * Configuration:
     * <BR> equals -- the value to be matched
     */
    @Override
	public void config(Configuration cfg, byte dataType)
	throws configException
    {
	String evals = (String)cfg.findSingle("equals");
	if (evals == null) {
	    throw new configException("\'equals\' attribute is not defined for the ExactRange");
	}
	else {
	    switch (dataType) {
	    case Decoder.INT_TYPE: 
		reference = Integer.valueOf(evals); break;
	    case Decoder.SHORT_TYPE:
		reference = Short.valueOf(evals); break;
	    case Decoder.BYTE_TYPE:
		reference = Byte.valueOf(evals); break;
	    case Decoder.FLOAT_TYPE:
		reference = Float.valueOf(evals); break;
	    case Decoder.STRING_TYPE:
		reference = evals; break;
	    case Decoder.IP_TYPE:
		reference = evals; break;
	    case Decoder.LONG_TYPE:
		reference = Long.valueOf(evals); break;
		
	    default:
		System.err.println("fieldType undefined.when config the ExactRange");
	    }	     
	}
    }

    @Override
	public boolean inRange(Object data, byte dataType)
    {
	if (data == null) return false;
	else return data.equals(reference);
    }

    
}
